package com.example.modulepicselector;

import android.app.Activity;
import android.content.Intent;
import androidx.fragment.app.Fragment;

import com.example.modulepicselector.engine.ImageEngine;
import com.example.modulepicselector.internal.entity.SelectionSpec;
import com.example.modulepicselector.view.activity.MatActivity;

public class MySelectionCreator {

    private final SelectionSpec mSelectionSpec;
    private final MyMatisse mMatisse;

    public MySelectionCreator(MyMatisse matisse) {
        mMatisse = matisse;
        mSelectionSpec = SelectionSpec.getCleanInstance();
    }

    public MySelectionCreator countable(boolean countable) {
        mSelectionSpec.countable = countable;
        return this;
    }

    public MySelectionCreator maxSelectable(int maxSelectable) {
        if (maxSelectable < 1)
            throw new IllegalArgumentException("至少都要選擇1個");
        mSelectionSpec.maxSelectable = maxSelectable;
        return this;
    }


    public MySelectionCreator imageEngine(ImageEngine imageEngine) {
        mSelectionSpec.imageEngine = imageEngine;
        return this;
    }



    public void forResult(int requestCode) {
        Activity activity = mMatisse.getActivity();
        if (activity == null) {
            return;
        }
        Intent intent = new Intent(activity, MatActivity.class);

        Fragment fragment = mMatisse.getFragment();
        if (fragment != null) {
            fragment.startActivityForResult(intent, requestCode);
        } else {
            activity.startActivityForResult(intent, requestCode);
        }
    }

}
